<?php
/**
* @version $Id: admin.users.html.php 10002 2008-02-08 10:56:57Z willebil $
* @package Joomla
* @subpackage Users
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

/**
* @package Joomla
* @subpackage Users
*/
class HTML_users {

	function showUsers( &$rows, $pageNav, $search, $option, $lists ) {
		global $mosConfig_live_site;
		?>
		<form action="index2.php" method="post" name="adminForm">

		<table class="adminheading">
		<tr>
			<th class="user">
			Quản lý thành viên
			</th>
			<td>
			Tìm:
			</td>
			<td>
			<input type="text" name="search" value="<?php echo htmlspecialchars( $search );?>" class="inputbox" onChange="document.adminForm.submit();" />
			</td>
			<td width="right">
			<?php echo $lists['type'];?>
			</td>
			<td width="right">
			<?php echo $lists['logged'];?>
			</td>
		</tr>
		</table>

		<table class="adminlist">
		<tr>
			<th width="2%" class="title">
			#
			</th>
			<th width="3%" class="title">
			<input type="checkbox" name="toggle" value="" onClick="checkAll(<?php echo count($rows); ?>);" />
			</th>
			<th class="title">
			Tên thành viên
			</th>
			<th width="15%" class="title" >
			Tên đăng nhập
			</th>
			<th width="10%" class="title" >
			Nhóm thành viên
			</th>
			<th width="5%" class="title">
			<b style="color:red;">VIP</b>
			</th>
			<th width="5%" class="title" nowrap="nowrap">
			Đăng nhập?
			</th>
			<th width="5%" class="title">
			Kích hoạt
			</th>
			<th width="15%" class="title">
			Kiểu thành viên
			</th>
			<th width="15%" class="title">
			E-Mail
			</th>
			<th width="10%" class="title">
			Ngày đăng ký
			</th>
			<th width="1%" class="title">
			ID
			</th>
		</tr>
		<?php
		$k = 0;
		for ($i=0, $n=count( $rows ); $i < $n; $i++) {
			$row 	=& $rows[$i];

			$img 	= $row->block ? 'publish_x.png' : 'tick.png';
			$task 	= $row->block ? 'unblock' : 'block';
			$alt 	= $row->block ? 'Enabled' : 'Blocked';
			$link 	= 'index2.php?option=com_users&amp;task=editA&amp;id='. $row->id. '&amp;hidemainmenu=1';
			?>
			<tr class="<?php echo "row$k"; ?>">
				<td>
				<?php echo $i+1+$pageNav->limitstart;?>
				</td>
				<td>
				<?php echo mosHTML::idBox( $i, $row->id ); ?>
				</td>
				<td>
				<a href="<?php echo $link; ?>">
				<?php echo $row->name; ?>
				</a>
				<td>
				<?php echo $row->username; ?>
				</td>
				<td>
				<?php if ($row->user_class == 1) echo '<b>Nhà cung cấp</b>'; else echo 'Thành viên thường'; ?>
				</td>
				<td>
				<?php
				if($row->vip==1){
				?>
				<img src="<?php echo $mosConfig_live_site;?>/images/vip.png" width="20" border="0" />
				<?php
				}
				?>
				</td>
				</td>
				<td align="center">
				<?php echo $row->loggedin ? '<img src="images/tick.png" width="12" height="12" border="0" alt="" />': ''; ?>
				</td>
				<td>
				<a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')">
				<img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="<?php echo $alt; ?>" />
				</a>
				</td>
				<td>
				<?php echo $row->groupname; ?>
				</td>
				<td>
				<a href="mailto:<?php echo $row->email; ?>">
				<?php echo $row->email; ?>
				</a>
				</td>
				<td nowrap="nowrap">
				<?php echo mosFormatDate( $row->registerDate, _CURRENT_SERVER_TIME_FORMAT ); ?>
				</td>
				<td>
				<?php echo $row->id; ?>
				</td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<?php echo $pageNav->getListFooter(); ?>

		<input type="hidden" name="option" value="<?php echo $option;?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="hidemainmenu" value="0" />
		<input type="hidden" name="<?php echo josSpoofValue(); ?>" value="1" />
		</form>
		<?php
	}

	function edituser( &$row, &$contact, &$lists, $option, $uid, &$params, &$listCity, &$lsDistrict ) {
		global $my, $acl;
		global $mosConfig_live_site;
		global $database;

		mosMakeHtmlSafe( $row );

		$tabs = new mosTabs( 0 );

		mosCommonHTML::loadOverlib();
		$canBlockUser 	= $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'user properties', 'block_user' );
		$canEmailEvents = $acl->acl_check( 'workflow', 'email_events', 'users', $acl->get_group_name( $row->gid, 'ARO' ) );
		?>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site; ?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
		<link rel="stylesheet" href="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.css" type="text/css" />
		<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript">
		function delete_extra_options (selobj, size)
		{
			while (selobj . options . length > size)
				selobj . options [selobj . options . length - 1] = null;
		}
		
		function update_item_list ()
		{
			var cat_selobj = document . adminForm . city_id;
			var item_selobj = document . adminForm . district_id;
			var choice = cat_selobj . options [cat_selobj . selectedIndex] . value;
			<?php
			for ($i=0; $i<count($listCity); $i++){
				?>
				if (choice == <?php echo $listCity[$i]->id;?>)
				{
					<?php
					$sql = "select count(*) from #__district where published=1 and city_id=".$listCity[$i]->id;
					$database->setQuery($sql);
					$total = $database->loadResult();
					$sql = "select * from #__district where published=1 and city_id=".$listCity[$i]->id." order by title asc, id desc";
					$database->setQuery($sql);
					$listDistrict = $database->loadObjectList();
					for ($j=0; $j<count($listDistrict); $j++){
					?>
					item_selobj . options [<?php echo $j;?>] = new Option ("<?php echo $listDistrict[$j]->title;?>","<?php echo $listDistrict[$j]->id;?>");
					<?php
					}
					?>
					delete_extra_options (item_selobj, <?php echo $total;?>);
				}
				<?php
			}
			?>
		}
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == 'cancel') {
				submitform( pressbutton );
				return;
			}
			var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");

			// do field validation
			if (trim(form.name.value) == "") {
				alert( "Bạn phải cung cấp tên thành viên !" );
			} else if (form.username.value == "") {
				alert( "Bạn phải cung cấp tên đăng nhập !" );
			} else if (r.exec(form.username.value) || form.username.value.length < 3) {
				alert( "Bạn cung cấp tên có chứa các ký tự không hợp lệ hoặc quá ngắn !" );
			} else if (trim(form.email.value) == "") {
				alert( "Bạn phải cung cấp địa chỉ e-mail có thực !" );
			} else if (form.gid.value == "") {
				alert( "Bạn phải chọn nhóm thành viên !" );
			} else if (trim(form.password.value) != "" && form.password.value != form.password2.value){
				alert( "Mật khẩu không phù hợp." );
			} else if (form.gid.value == "29") {
				alert( "Vui lòng lựa chọn một nhóm khác như `Public Front-end` không phải là một lựa chọn !" );
			} else if (form.gid.value == "30") {
				alert( "Vui lòng lựa chọn một nhóm khác như `Public Back-end` không phải là một lựa chọn !" );
			} else if (form.user_class.value == "") {
				alert( "Vui lòng lựa chọn nhóm thành viên." );
			}else {
				submitform( pressbutton );
			}
		}

		function gotocontact( id ) {
			var form = document.adminForm;
			form.contact_id.value = id;
			submitform( 'contact' );
		}
		$(document).ready(function() {
			<?php 
    		if ($row->user_class==1){
	    		?>
	    		$('.user_normal').hide();
	    		<?php 
			}else{
	    		?>
	    		$('.user_normal').show();
	    		<?php 
			}
    		?>
    		//load change user_class
    		$('select[name=user_class]').change(function(){
        		var val = $('select[name=user_class]').val();
        		if (val == 1) $('.user_normal').hide();
        		else $('.user_normal').show();
        	});
			//Load editor
	    	$(function()
    		{
    			$('#wysiwyg').wysiwyg();
    		});
	    });
		</script>
		<form action="index2.php" method="post" name="adminForm" enctype="multipart/form-data">

		<table class="adminheading">
		<tr>
			<th class="user">
			Thành viên: <small><?php echo $row->id ? 'Edit' : 'Add';?></small>
			</th>
		</tr>
		</table>

		<table width="100%">
		<tr>
			<td width="50%" valign="top">
				<table class="adminform">
				<tr>
					<th colspan="2">
					Thông tin thành viên
					</th>
				</tr>
				<tr>
					<td width="130">
					Tên đầy đủ:
					</td>
					<td>
					<input type="text" name="name" class="inputbox" size="40" value="<?php echo $row->name; ?>" maxlength="50" />
					</td>
				</tr>
				<tr>
					<td>
					Tên đăng nhập:
					</td>
					<td>
					<input type="text" name="username" class="inputbox" size="40" value="<?php echo $row->username; ?>" maxlength="25" />
					</td>
				<tr>
					<td>
					E-mail:
					</td>
					<td>
					<input class="inputbox" type="text" name="email" size="40" value="<?php echo $row->email; ?>" />
					</td>
				</tr>
				<tr>
					<td>
					Mật khẩu mới:
					</td>
					<td>
					<input class="inputbox" type="password" name="password" size="40" value="" />
					</td>
				</tr>
				<tr>
					<td>
					Xác nhận mật khẩu:
					</td>
					<td>
					<input class="inputbox" type="password" name="password2" size="40" value="" />
					</td>
				</tr>
				<tr>
					<td valign="top">
					Kiểu thành viên:
					</td>
					<td>
					<?php echo $lists['gid']; ?>
					</td>
				</tr>
				<tr>
					<td valign="top">
					Nhóm thành viên:
					</td>
					<td>
					<select name="user_class" onchange="javascript:showTable(this.value);">
						<option value="">Lựa chọn theo nhóm</option>
						<option value="0"<?php if($row->user_class==0) echo ' selected="selected"';?>>Thành viên thường</option>
						<option value="1"<?php if($row->user_class==1) echo ' selected="selected"';?>>Nhà cung cấp sản phẩm</option>
					</select>
					</td>
				</tr>
				<tr>
					<td valign="top">
					Thành viên VIP :
					</td>
					<td>
					<input type="checkbox" class="inputbox" name="vip" value="1"<?php if($row->vip==1) echo ' checked="checked"';?> /> <b style="color:red;">VIP</b>
					</td>
				</tr>
				<?php
				if ($canBlockUser) {
					?>
					<tr>
						<td>
						Thành viên bị khóa
						</td>
						<td>
						<?php echo $lists['block']; ?>
						</td>
					</tr>
					<?php
				}
				if ($canEmailEvents) {
					?>
					<tr>
						<td>
						Tiếp nhận hệ thống e-mail
						</td>
						<td>
						<?php echo $lists['sendEmail']; ?>
						</td>
					</tr>
					<?php
				}
				if( $uid ) {
					?>
					<tr>
						<td>
						Register Date
						</td>
						<td>
						<?php echo $row->registerDate;?>
						</td>
					</tr>
				<tr>
					<td>
					Ngày đăng nhập gần nhất
					</td>
					<td>
					<?php echo $row->lastvisitDate;?>
					</td>
				</tr>
					<?php
				}
				?>
				<tr>
					<td colspan="2">&nbsp;

					</td>
				</tr>
				</table>
			</td>
			<td width="50%" valign="top">
				<table class="adminform">
				<tr>
					<th colspan="1">
					<?php echo 'Parameters'; ?>
					</th>
				</tr>
				<tr>
					<td>
					<?php echo $params->render( 'params' );?>
					</td>
				</tr>
				</table>
				<div id="show">
				<table class="adminform" id="show_member">
				<tr>
					<th colspan="2">
					<?php
					if ($row->user_class==1){
						echo 'Nhà cung cấp sản phẩm';
					}
					else{
						echo 'Thành viên thường';
					}
					?>					
					</th>
				</tr>
				<tr>
					<td valign="top">
					<?php
					if ($row->user_class==1){
						echo 'Logo công ty';
						$name_dir = 'logo';
					}else{
						echo 'Avatar cá nhân';
						$name_dir = 'avatar';
					}
					?>					
					</td>
					<td>
					<img src="<?php echo $mosConfig_live_site;?>/uploads/users/<?php echo $name_dir."/".$row->img;?>" width="130" border="0" />
					<br />
					<input type="file" name="img" size="30" />
					</td>
				</tr>
				<tr>
					<td><?php echo _REGISTER_ADDRESS; ?> :</td>
					<td><input class="inputbox" type="text" name="address" value="<?php echo $row->address;?>" size="40" /></td>
				</tr>
				<tr>
					<td align="right">
						<?php echo _REGISTER_CITY_ID; ?>
					</td>
					<td align="left">
						<select onChange="update_item_list();" size="1" name="city_id" id="city_id" title="Chọn" class="inputbox" style="width:150px;">
							<option value="">--[Chọn]--</option>
							<?php
							for ($i=0; $i<count($listCity); $i++){
								if ($listCity[$i]->id == $row->city_id) $selected = ' selected="selected"';
								else $selected = '';
								echo "<option value='".$listCity[$i]->id."'".$selected.">".$listCity[$i]->title."</option>";
							}
							?> 
						</select>
					</td>
				</tr>
				<tr>
					<td align="right">
						<?php echo _REGISTER_DISTRICT_ID; ?>
					</td>
					<td align="left">
						<select onchange="" size="1" name="district_id" id="district_id" title="Chọn" class="inputbox" style="width:150px;">
							<?php
							for ($i=0; $i<count($lsDistrict); $i++){
								if ($lsDistrict[$i]->id == $row->district_id) $selected = ' selected="selected"';
								else $selected = '';
								echo "<option value='".$lsDistrict[$i]->id."'".$selected.">".$lsDistrict[$i]->title."</option>";
							}
							?> 
						</select>
					</td>
				</tr>
				<tr>
					<td><?php echo _REGISTER_MOBILE; ?> :</td>
					<td><input class="inputbox" type="text" name="mobile" value="<?php echo $row->mobile;?>" size="40" /></td>
				</tr>
				<tr class="user_normal">
					<td align="right">
						<?php echo _REGISTER_SEX; ?>
					</td>
					<td align="left">
						<select onchange="" size="1" name="sex" id="sex" title="Chọn" class="inputbox" style="width:80px;">
							<option value="1"<?php if ($row->sex==1) echo ' selected="selected"';?>>Nam</option>
							<option value="0"<?php if ($row->sex==0) echo ' selected="selected"';?>>Nữ</option>
						</select>
					</td>
				</tr>
				<tr class="user_normal">
					<td align="right">
						<?php echo _REGISTER_BIRTHDAY; ?>
					</td>
					<td align="left">
						<input class="inputbox" type="text" name="birthday" id="birthday" size="25" style="width:150px;" value="<?php echo $row->birthday;?>" />
						<input name="reset" type="reset" class="button" onclick="return showCalendar('birthday', 'y-mm-dd');" value="..." />
					</td>
				</tr>
				<tr>
					<td><?php echo _REGISTER_YAHOO; ?> :</td>
					<td><input class="inputbox" type="text" name="yahoo" value="<?php echo $row->yahoo;?>" size="40" /></td>
				</tr>
				<tr>
					<td><?php echo _REGISTER_SKYPE; ?> :</td>
					<td><input class="inputbox" type="text" name="skype" value="<?php echo $row->skype;?>" size="40" /></td>
				</tr>
				<tr>
					<td><?php echo _REGISTER_WEBSITE; ?> :</td>
					<td><input class="inputbox" type="text" name="website" value="<?php echo $row->id ? $row->website : 'http://';?>" size="40" /></td>
				</tr>
				<tr>
					<td valign="top"><?php echo _REGISTER_ABOUTS; ?> :</td>
					<td><textarea name="content" id="wysiwyg" cols="46" rows="12"><?php echo $row->content;?></textarea></td>
				</tr>	
				</table>				
				</div>
				<?php
				if ( !$contact ) {
					?>
					<table class="adminform">
					<tr>
						<th>
						Contact Information
						</th>
					</tr>
					<tr>
						<td>
						<br />
						No Contact details linked to this User:
						<br />
						See 'Components -> Contact -> Manage Contacts' for details.
						<br /><br />
						</td>
					</tr>
					</table>
					<?php
				} else {
					?>
					<table class="adminform">
					<tr>
						<th colspan="2">
						Contact Information
						</th>
					</tr>
					<tr>
						<td width="15%">
						Name:
						</td>
						<td>
						<strong>
						<?php echo $contact[0]->name;?>
						</strong>
						</td>
					</tr>
					<tr>
						<td>
						Position:
						</td>
						<td >
						<strong>
						<?php echo $contact[0]->con_position;?>
						</strong>
						</td>
					</tr>
					<tr>
						<td>
						Telephone:
						</td>
						<td >
						<strong>
						<?php echo $contact[0]->telephone;?>
						</strong>
						</td>
					</tr>
					<tr>
						<td>
						Fax:
						</td>
						<td >
						<strong>
						<?php echo $contact[0]->fax;?>
						</strong>
						</td>
					</tr>
					<tr>
						<td></td>
						<td >
						<strong>
						<?php echo $contact[0]->misc;?>
						</strong>
						</td>
					</tr>
					<?php
					if ($contact[0]->image) {
						?>
						<tr>
							<td></td>
							<td valign="top">
							<img src="<?php echo $mosConfig_live_site;?>/images/stories/<?php echo $contact[0]->image; ?>" align="middle" alt="Contact" />
							</td>
						</tr>
						<?php
					}
					?>
					<tr>
						<td colspan="2">
						<br /><br />
						<input class="button" type="button" value="change Contact Details" onclick="javascript: gotocontact( '<?php echo $contact[0]->id; ?>' )">
						<i>
						<br />
						'Components -> Contact -> Manage Contacts'.
						</i>
						</td>
					</tr>
					</table>
					<?php
				}
				?>
			</td>
		</tr>
		</table>

		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="contact_id" value="" />
		<?php
		if (!$canEmailEvents) {
			?>
			<input type="hidden" name="sendEmail" value="0" />
			<?php
		}
		?>
		<input type="hidden" name="<?php echo josSpoofValue(); ?>" value="1" />
		</form>
		<?php
	}
}
?>
